package cn.lzg.server.module.user.dao;

import org.springframework.stereotype.Repository;

import cn.lzg.server.module.user.entity.User;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

@Repository
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	@Resource(name = "sessionFactory")
	public void setSessionFacotry(SessionFactory sessionFacotry) {
		super.setSessionFactory(sessionFacotry);
	}

	public UserDaoImpl() {
	}

	@Override
	public User findUserById(String id) {
		return this.getHibernateTemplate().get(User.class, id);
	}

	@Override
	public User findUserByName(String username) {
		return (User) this.getHibernateTemplate().findByNamedParam("from user", username, username);
	}

	@Override
	public void addUser(User user) {
		this.getHibernateTemplate().save(user);
	}

}
